<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>修改评论信息</title>
    <link rel="stylesheet" href="./css/style.css">
    <!--引入vue相关的js文件-->
    <script src="./js/vue.js"></script>
    <script src="./js/axios.min.js"></script>
</head>
<body>
<div class="container" id="app">
    <h2>修改评论信息</h2>
    <form id="editEmployeeForm" action="javascript:void(0)">
<!--        <input type="hidden" id="editEmpId" name="empId">-->
        <!-- 其他字段类似新增页面 -->
        <div class="form-group">
            <label for="paper_id">评论id</label>
            <input v-model="editCommentData.comment_id" type="text" id="comment_id" name="comment_id" required>
        </div>
        <div class="form-group">
            <label for="paper_id">文章id</label>
            <input v-model="editCommentData.paper_id" type="text" id="paper_id" name="paper_id" required>
        </div>
        <div class="form-group">
            <label for="user_id">评论id</label>
            <input v-model="editCommentData.user_id" type="text" id="user_id" name="user_id" required>
        </div>
        <div class="form-group">
            <label for="publish_date">发布日期</label>
            <input v-model="editCommentData.publish_date" type="date" id="publish_date" name="publish_date" required>
        </div>
        <div class="form-group">
            <label for="like_count">点赞人数</label>
            <input v-model="editCommentData.like_count" type="text" id="like_count" name="like_count" required>
        </div>
        <div class="form-group">
            <label for="favorite_count">收藏人数</label>
            <input v-model="editCommentData.favorite_count" type="text" id="favorite_count" name="favorite_count" required>
        </div>
        <div class="form-group">
            <label for="content">评论内容</label>
            <input v-model="editCommentData.content" type="text" id="content" name="content"
                   required>
        </div>
        <button @click="editComment">保存修改</button>
    </form>
</div>
<script>
    new Vue({
        el:"#app",
        created:function () {
            this.getCommentById();
        },
        data:{
            editCommentData:{
                comment_id: '',
                paper_id: '',
                user_id: '',
                publish_date: '',
                like_count: '',
                favorite_count: '',
                content: ''
            }
        },
        methods:{
            getCommentById:function () {
                let comment_id = localStorage.getItem("comment_id");
                axios({
                    url:"/pns/getCommentById",
                    method:"get",
                    params:{comment_id: comment_id}
                }).then(result=>{
                    let code = result.data.code;
                    if (code == "200"){
                        this.editCommentData = result.data.data;
                    }
                });
            },
            editComment:function () {
                axios({
                    url:"/pns/updateComment",
                    method:"get",
                    params:this.editCommentData
                }).then(result=>{
                    let code = result.data.code;
                    if (code == "200"){
                        alert("修改成功");
                        //重新查询
                        location.href="/pns/comment.html"
                    }else{
                        alert(result.data.msg);
                    }
                });
            }
        }
    });
</script>
</body>
</html>